package com.yang.strategy.flter.impl;

import com.yang.common.constant.CacheConstant;
import com.yang.common.constant.RabbitMQConstants;
import com.yang.common.constant.SmsConstant;
import com.yang.common.enums.ExceptionEnums;
import com.yang.common.exception.StrategyException;
import com.yang.common.model.StandardReport;
import com.yang.common.model.StandardSubmit;
import com.yang.strategy.client.BeaconCacheClient;
import com.yang.strategy.flter.StrategyFilter;
import com.yang.strategy.util.ErrorSendMsgUtil;
import com.yang.strategy.util.HutoolDFAUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.misc.Cache;

import java.util.List;

/**
 * @author yangyongsheng
 * @date 2024/9/7 23:44
 * @description
 */
@Service(value = "hutoolDFADirtyWord")
@Slf4j
public class DirtyWordHutoolDFAStrategyFilter implements StrategyFilter {

    @Autowired
    private ErrorSendMsgUtil errorSendMsgUtil;


    @Override
    public void strategy(StandardSubmit submit) {
        log.info("【策略模块-敏感词校验】   校验ing…………");
        //1、 获取短信内容
        String text = submit.getText();

        //2、 调用DFA查看敏感词
        List<String> dirtyWords = HutoolDFAUtil.getDirtyWord(text);

        //4、 根据返回的set集合，判断是否包含敏感词
        if (dirtyWords != null && dirtyWords.size() > 0) {
            //存在敏感词
            log.info("【策略模块-敏感词校验】   短信内容包含敏感词信息， dirtyWords = {}", dirtyWords);
            //封装错误信息
            submit.setErrorMsg(ExceptionEnums.HAVE_DIRTY_WORD.getMsg() + "dirtyWords = " + dirtyWords.toString());
            //发送写日志操作
            errorSendMsgUtil.sendWriteLog(submit);
            //发送状态报告操作
            errorSendMsgUtil.sendPushReport(submit);

            //抛异常
            throw new StrategyException(ExceptionEnums.HAVE_DIRTY_WORD);
        }

        log.info("【策略模块-敏感词校验】   校验通过…………");
    }
}